home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / TREE.AML < prev    next >
Text File  |  1996-07-17  |  20KB  |  789 lines

  1. //--------------------------------------------------------------------
  2. // DIRTREE.AML
  3. // Directory Tree, (C) 1993-1996 by nuText Systems
  4. //
  5. // (see Tree.dox for user help)
  6. //
  7. // This macro displays an expandable/collapsable directory tree for your
  8. // computer.
  9. //
  10. // Usage:
  11. //
  12. // Select this macro from the Macro List (on the Macro menu), or run it
  13. // from the macro picklist <shift f12>.
  14. //
  15. // This macro can also be run by selecting 'Tree..' on the File menu.
  16. //--------------------------------------------------------------------
  17.  
  18. // compile time macros and function definitions
  19. include  bootpath "define.aml"
  20.  
  21. // initial tree window width
  22. constant tree_width  = 42
  23.  
  24. // colors
  25. constant tree_border_color        = color black on gray
  26. constant tree_border_flash_color  = color brightgreen on gray
  27. constant tree_south_title_color   = color black on green
  28. constant tree_text_color          = color black on gray
  29. constant tree_cursor_color        = color black on brightgreen
  30. constant tree_plus_color          = color brown on gray
  31. constant tree_menu_color          = color black on green
  32. constant tree_menu_hotkey_color   = color red
  33. constant tree_menu_hilite_color   = color black on brightgreen
  34.  
  35. // syntax object for directory tree window
  36. object xtree
  37.  
  38.   syntax
  39.     'bcfd'                          // options:
  40.                                     //   b=show through marked block
  41.                                     //   c=highlight cursor line
  42.                                     //   d=show through closed folds
  43.                                     //   f=use only foreground colors
  44.                                     //   i=ignore keyword case
  45.                                     //   n=highlight numbers
  46.     '└─├│-'                         // symbol set 1
  47.     '+'                             // symbol set 2
  48.     ''                              // string characters
  49.     ''                              // string literal char
  50.     ''                              // numeric symbol
  51.     ''            0                 // eol comment 1 / start column
  52.     ''            0                 // eol comment 2 / start column
  53.     ''            ''                // multi-line comment 1
  54.     ''            ''                // multi-line comment 2
  55.     0                               // number of lines to scan backward
  56.  
  57.     // colors
  58.     color brightcyan   on black        // keyword
  59.     color darkgray     on gray         // symbol set 1
  60.     color brown        on gray         // symbol set 2
  61.     color brightred    on brightred    // string
  62.     color brightred    on brightred    // numeric
  63.     color darkgray     on gray         // eol comment 1
  64.     color yellow       on yellow       // eol comment 2
  65.     color brightgreen  on brightgreen  // comment 1
  66.     color brightcyan   on brightcyan   // comment 2
  67.  
  68. // go back to original object
  69. object entry
  70.  
  71. forward opendir
  72. forward edittree
  73. forward refreshtree
  74.  
  75. forward insertdir
  76. forward deletedir
  77. forward renamedir
  78. forward printdir
  79. forward statdir
  80.  
  81. forward openbr
  82. forward openall
  83. forward closebr
  84. forward closeblock
  85. forward closeall
  86.  
  87. forward printtree
  88. forward helptree
  89.  
  90.  
  91. variable treewindow, resultbuf, dircount, currentdrive, nomsg, initialpath
  92. variable showfiles
  93.  
  94.  
  95. leftmargin = 1
  96.  
  97. // create the dirtree window
  98. private function createtreewin
  99.  
  100.   treewindow = createwindow
  101.   setframe  ">bsmvh"
  102.   setcolor  border_color        tree_border_color
  103.   setcolor  north_title_color   tree_border_color
  104.   setcolor  text_color          tree_text_color
  105.   setcolor  fold_color          tree_text_color
  106.   setcolor  border_flash_color  tree_border_flash_color
  107.   setcolor  south_title_color   tree_south_title_color
  108.   setcolor  menu_color          tree_menu_color
  109.   setcolor  menu_hotkey_color   tree_menu_hotkey_color
  110.   setcolor  menu_hilite_color   tree_menu_hilite_color
  111.   settitle "Tree"
  112.   setwinctrl "≡" 2
  113.   setborder "1"
  114.   setshadow 2 1
  115.   setsyntax ON "xtree"
  116.   prf.dirtree = prf.dirtree + 1
  117.  
  118.   menubar '' 1
  119.     item "&File"           "Tfile"
  120.     item "&View"           "Tview"
  121.     item "&Print"          "Tprint"
  122.     item "&Window"         "Twin"
  123.     item "&Help"           "Thelp"
  124.   end
  125.  
  126.   menu "Tfile"
  127.     item " &Open             <enter>"  opendir
  128.     item " &Print"                     printdir
  129.     item " &Statistics..    <ctrl v>"  statdir
  130.     item "-"
  131.     item " &Delete             <del>"  deletedir
  132.     item " &Insert..           <ins>"  insertdir
  133.     item " Re&name..        <ctrl n>"  renamedir
  134.     item "─"
  135.     item " &Edit Tree       <ctrl e>"  edittree
  136.     item " &Refresh..       <ctrl r>"  refreshtree
  137.     item "-"
  138.     item " &Close              <esc>"  destroyobject
  139.   end
  140.  
  141.   menu "Tview"
  142.     item " &Close Branch                <shift left>"   closebr
  143.     item " Close &All Branches            <alt left>"   closeall
  144.     item "-"
  145.     item " &Open Branch                <shift right>"   openbr '' 1
  146.     item " Open Branch with &Files      <ctrl right>"   openbr 'f' 1
  147.     item " Open All &Branches            <alt right>"   openall
  148.     item " O&pen All Branches with Files"               openall 'f'
  149.   end
  150.  
  151.   menu "Tprint"
  152.     item " &Print Tree        <ctrl p>"   printtree
  153.     item " Print &Formfeed"               printstr '\x0C'
  154.     item " Print &Settings..|*"           runcfg "print"
  155.   end
  156.  
  157.   menu "Twin"
  158.     item " &Restore"                       restore
  159.     item " &Move/Size         <ctrl f5>"   sizekey
  160.     item " M&inimize"                      minimize
  161.     item " Ma&ximize           <ctrl z>"   maximize
  162.     item " &Next               <ctrl a>"   nextwindow
  163.     item "─"
  164.     item " Ca&scade          <shift f5>"   cascade
  165.     item " Tile &Horz        <shift f4>"   tile 'h'
  166.     item " Tile &Vert        <shift f3>"   tile 'v'
  167.   end
  168.  
  169.   menu "Thelp"
  170.     item " &Keys and Mouse.."    helptree
  171.   end
  172.  
  173.   // center the window
  174.   width  = tree_width
  175.   height = getvidrows - 5
  176.   ox = (getvidcols - width) / 2
  177.   oy = (getvidrows - height) / 2
  178.   sizewindow ox oy ox + width oy + height "ad"
  179. end
  180.  
  181. diroptions = 'dhvs' + _NameStyle
  182. fileoptions = 'dfhvs' + _NameStyle
  183.  
  184. private function scandir (path directory treestr expand)
  185.  
  186.   addline treestr + directory '' '' resultbuf
  187.  
  188.   // scan window status line
  189.   dircount = dircount + 1
  190.   if not nomsg then
  191.     settitle  "Directories/Files: " + dircount 'sl' 2
  192.     display
  193.   end
  194.  
  195.   // get a directory listing
  196.   path = path + directory + '\\'
  197.  
  198.   // load files if specified
  199.   if expand and showfiles then
  200.     if loadbuf path + "*.*" '' '' fileoptions then
  201.       if getloadinfo 'f' then
  202.         treestrfile = treestr
  203.         if length treestrfile > leftmargin then
  204.           treestrfile [length treestrfile - 3..TO_END] =
  205.             if? treestrfile [length treestrfile - 3] == '└'  "    "  "│   "
  206.         end
  207.         treestrfile = treestrfile + (if? (getloadinfo 'd') "│   " "    ")
  208.         // sort the listing
  209.         sortblock '' "*a"
  210.         repeat
  211.           line = gettext
  212.           if not pos '\\' line then
  213.             addline treestrfile + line '' '' resultbuf
  214.           end
  215.         until not down
  216.       end
  217.       destroybuf
  218.     end
  219.   end
  220.  
  221.   if loadbuf path + "*.*" '' '' diroptions then
  222.     if getloadinfo 'd' then
  223.       if not expand then
  224.         if initialpath and (pos path initialpath) == 1 and
  225.            length path < length initialpath then
  226.           expand = 1
  227.         elseif length treestr > leftmargin then
  228.           ovltext "+ "  (length treestr - 1) (getlines resultbuf) resultbuf
  229.         end
  230.       end
  231.       if expand then
  232.         if length treestr > leftmargin then
  233.           treestr [length treestr - 3..TO_END] =
  234.             if? treestr [length treestr - 3] == '└'  "    "  "│   "
  235.         end
  236.  
  237.         // sort the directory listing
  238.         sortblock '' "*a"
  239.         repeat
  240.           scandir path gettext [1 : getlinelen - 1]
  241.                   treestr + (if? getrow == getlines "└── " "├── ") expand - 1
  242.         until not down
  243.       end
  244.     end
  245.     destroybuf
  246.   end
  247.  
  248. end
  249.  
  250.  
  251. // get system drives (except floppies)
  252. drives = sub 'B' '' (